package com.boco.modules.fdoc.service.impl;

import javax.annotation.Resource;

import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import com.boco.modules.fdoc.dao.UserDao;
import com.boco.modules.fdoc.model.UserEntity;
import com.boco.modules.fdoc.service.UserService;
import com.boco.modules.fdoc.vo.UserVo;

@Service
public class UserServiceImpl implements UserService {

	@Resource
	UserDao userDao;
	
	@Override
	public UserEntity getUser(String uid) {
		return userDao.get(uid);
	}

	@Override
	public int updateUser(UserVo vo) {
		UserEntity entity  = new UserEntity();
		BeanUtils.copyProperties(vo, entity);
		return userDao.update(entity);
	}

	@Override
	public int updateMobile(UserVo vo) {
		return userDao.updateMobile(vo);
	}

	@Override
	public int updatePassword(UserVo vo) {
		return userDao.updatePassword(vo);
	}

	@Override
	public int forgotPsw(UserVo vo) {
		UserEntity userEntity = new UserEntity();
		userEntity.setMobile(vo.getMobile());
		userEntity.setPassword(vo.getPassword());
		userEntity = userDao.findByMobileAndPsw(userEntity);
		if (userEntity != null) {
			return 0;
		}else {
			return userDao.forgotPsw(vo);
		}
	}

}
